
import java.util.Date;
import java.util.HashSet;

/**
 * 
 */

/**
 * @author Andreas Waldherr (e1028787@student.tuwien.ac.at)
 *
 */
public class Course {

	private String courseID;
	private String courseName;
	private Date registerStart;
	private Date registerEnd;
	private Date unregisterEnd;
	private HashSet<Student> registeredStudents;
	
	/**
	 * @param courseID
	 * @param courseName
	 * @param registerStart
	 * @param registerEnd
	 * @param unregisterEnd
	 */
	protected Course(String courseID, String courseName, Date registerStart, Date registerEnd, Date unregisterEnd){
		setCourseID(courseID);
		setCourseName(courseName);
		setRegisterStart(registerStart);
		setRegisterEnd(registerEnd);
		setUnregisterEnd(unregisterEnd);
		setRegisteredStudents(new HashSet<Student>());
	}

	/**
	 * @return the courseID
	 */
	public String getCourseID() {
		return courseID;
	}

	/**
	 * @param courseID the courseID to set
	 */
	protected void setCourseID(String courseID) {
		this.courseID = courseID;
	}

	/**
	 * @return the courseName
	 */
	public String getCourseName() {
		return courseName;
	}

	/**
	 * @param courseName the courseName to set
	 */
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	/**
	 * @return the registerStart
	 */
	public Date getRegisterStart() {
		return registerStart;
	}

	/**
	 * @param registerStart the registerStart to set
	 */
	public void setRegisterStart(Date registerStart) {
		this.registerStart = registerStart;
	}

	/**
	 * @return the registerEnd
	 */
	public Date getRegisterEnd() {
		return registerEnd;
	}

	/**
	 * @param registerEnd the registerEnd to set
	 */
	public void setRegisterEnd(Date registerEnd) {
		this.registerEnd = registerEnd;
	}

	/**
	 * @return the unregisterEnd
	 */
	public Date getUnregisterEnd() {
		return unregisterEnd;
	}

	/**
	 * @param unregisterEnd the unregisterEnd to set
	 */
	public void setUnregisterEnd(Date unregisterEnd) {
		this.unregisterEnd = unregisterEnd;
	}

	/**
	 * @return the registeredStudents
	 */
	public HashSet<Student> getRegisteredStudents() {
		return registeredStudents;
	}

	/**
	 * @param registeredStudents the registeredStudents to set
	 */
	protected void setRegisteredStudents(HashSet<Student> registeredStudents) {
		this.registeredStudents = registeredStudents;
	}
	
	/**
	 * @return Number of registered Students.
	 */
	public int getNumberOfRegistrations(){
		return getRegisteredStudents().size();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((courseID == null) ? 0 : courseID.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Course other = (Course) obj;
		if (courseID == null) {
			if (other.courseID != null) {
				return false;
			}
		} else if (!courseID.equals(other.courseID)) {
			return false;
		}
		return true;
	}
	
	public String toString(){
		String ret = "LVA " + getCourseID() + ": " + getCourseName() + "\n" +
						"\tRegistration: " + getRegisterStart() + " - " + getRegisterEnd() + "\n" +
						"\tUn-register till: " + getUnregisterEnd() + "\n" + 
						getNumberOfRegistrations() + " already registered.";
		
		return ret;
	}
}
